<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Handlers\DingTalkHandler;
use Illuminate\Support\Facades\Log;
use EasyDingTalk\Application;

class DingTalkController extends Controller
{
    public function callback()
    {
        try {
            $app = new Application([
                'corp_id' => config('dingtalk.corp_id'),
                'app_key' => config('dingtalk.app_key'),
                'app_secret' => config('dingtalk.app_secret'),
                'token' => config('dingtalk.token'),
                'aes_key' => config('dingtalk.aes_key')
            ]);
            $server = $app->server;
            Log::info('callback');
            $server->push(DingTalkHandler::class);
            return $server->serve();
        } catch (\Exception $e) {
            Log::error($e->getMessage());
            return $e->getMessage();
        }
    }
}
